#include "TaskBoss.h"
#include "../../model/vo/ViewVO.h"
#include "../../model/static/StaticDungeons.h"
#include "../../model/proxy/DungeonsProxy.h"
#include "../../model/static/StaticItem.h"
#include "TaskBossLoader.h"
#include "../../model/proxy/FightProxy.h"
#include "../../net/NetController.h"

TaskBoss::TaskBoss( void )
	:mBossIcon(NULL), mName(NULL), mDesc(NULL), mExp(NULL), mCoin(NULL), mEnergy(NULL),
	mItemName(NULL),mEquipIcon(NULL)
{

}

TaskBoss::~TaskBoss( void )
{
	CC_SAFE_RELEASE(mName);
	CC_SAFE_RELEASE(mDesc);
	CC_SAFE_RELEASE(mExp);
	CC_SAFE_RELEASE(mCoin);
	CC_SAFE_RELEASE(mEnergy);
	CC_SAFE_RELEASE(mItemName);
}

bool TaskBoss::onAssignCCBMemberVariable( cocos2d::CCObject * pTarget, cocos2d::CCString * pMemberVariableName, cocos2d::CCNode * pNode )
{
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mDesc", CCLabelTTF *, this->mDesc);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mName", CCLabelTTF *, this->mName);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mExp", CCLabelTTF *, this->mExp);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mCoin", CCLabelTTF *, this->mCoin);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mEnergy", CCLabelTTF *, this->mEnergy);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mItemName", CCLabelTTF *, this->mItemName);
	return false;
}

void TaskBoss::onNodeLoaded( CCNode * pNode, CCNodeLoader * pNodeLoader )
{
	mBossIcon = new BossIcon();
	mBossIcon->setPosition(ccp(100,300));
	addChild(mBossIcon);
	mEquipIcon = EquipIcon::create(this);
	mEquipIcon->setPosition(40, 70);
	mEquipIcon->setScale(0.25);
	addChild(mEquipIcon);
}

bool TaskBoss::init()
{
	return true;
}

void TaskBoss::refresh()
{
	TaskStatic* taskInfo = DungeonsProxy::getSingletonPtr()->getCurTaskStatic();
	ItemStatic* itemStatic = StaticItem::getSingletonPtr()->getItemInfo(taskInfo->drop);
	mName->setString(g2u(taskInfo->name));
	mDesc->setString(g2u(taskInfo->desc));
	mItemName->setString(itemStatic->name);
	mBossIcon->bossID = taskInfo->bossID;
	mBossIcon->setIcon();
	mEquipIcon->setInfo(taskInfo->drop);
}

void TaskBoss::onDoItBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{
	//For Test
	NetController::getSingletonPtr()->dungeonExplore(
		DungeonsProxy::getSingletonPtr()->getCurDungeonsID(),
		DungeonsProxy::getSingletonPtr()->getCurFloorID(),
		DungeonsProxy::getSingletonPtr()->getCurTaskID());

	FightProxy::getSingletonPtr()->dungeons = DungeonsProxy::getSingletonPtr()->getCurDungeonsID();
	FightProxy::getSingletonPtr()->floor = DungeonsProxy::getSingletonPtr()->getCurFloorID();
	FightProxy::getSingletonPtr()->task = DungeonsProxy::getSingletonPtr()->getCurTaskID();
	//
	DungeonsProxy::getSingletonPtr()->curTaskInfo.floor++;
	DungeonsProxy::getSingletonPtr()->curTaskInfo.task++;
	DungeonsProxy::getSingletonPtr()->curTaskInfo.progress = 0;
	EquipInfo* ei = new EquipInfo();
	ei->atkMin = 10;
	ei->atkMax = 20;
	ei->defMin = 10;
	ei->defMax = 10;
	ei->exp = 100;
	ei->id = 30001;
	ei->index  = 6;
	ei->level = 2;
	ei->life = 20;
	ei->state = 0;
	Award& award = FightProxy::getSingletonPtr()->awardInfo;
	award.clear();
	award.coin = 10;
	award.exp = 10;
	award.equipList.push_back(ei);
	FightProxy::getSingletonPtr()->battleInfo.win = 2;
	Post_Net_Notification(kNCDungeonExplore, NULL);
}

cocos2d::SEL_MenuHandler TaskBoss::onResolveCCBCCMenuItemSelector( cocos2d::CCObject * pTarget, cocos2d::CCString * pSelectorName )
{
	return NULL;
}

cocos2d::extension::SEL_CCControlHandler TaskBoss::onResolveCCBCCControlSelector( cocos2d::CCObject * pTarget, cocos2d::CCString * pSelectorName )
{
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onDoItBtnClick", TaskBoss::onDoItBtnClick);
	return NULL;
}

TaskBoss* TaskBoss::create(CCObject* pOwer)
{
	RegisterLoader("TaskBoss", TaskBossLoader::loader());
	return (TaskBoss*)(ReadNode("TaskBoss.ccbi", pOwer));
}
